# core/codecs/dsd_converter.py
import libdsd

class DSDProcessor:
    def __init__(self, target_rate=2822400):
        self.resampler = libdsd.DSDResampler(
            mode=libdsd.MODE_SDM_TO_PCM,
            cutoff=0.49  # 优化抗混叠滤波器
        )
        
    def convert_dsd256_to_dsd128(self, input_file):
        with DSDReader(input_file) as reader:
            while True:
                chunk = reader.read(4096)
                if not chunk:
                    break
                # 应用改进的降频算法    
                output = self.resampler.process(
                    chunk,
                    decimation_factor=2,
                    noise_shaping=libdsd.SHAPING_III
                )
                yield output